﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;

using SBPweb.Forge.Controls.Silverlight.Utilities;

using SBPweb.Communication.Shared.Library.Contacts;

using SBPweb.Communication.Client.Controls.Xmpp;

namespace SBPweb.PROvibe.Modules.Client.Communication.Xmpp.Controls
{

    public partial class MessengerToolBar : UserControlBase
    {

        #region Private fields

        private ObservableCollection<ContactBase> manageableContacts = new ObservableCollection<ContactBase>();

        #endregion

        #region Constructor logic

        public MessengerToolBar()
        {
            InitializeComponent();
            manageableContacts.CollectionChanged += new NotifyCollectionChangedEventHandler(manageableContacts_CollectionChanged);
        }

        #endregion

        #region Property accessors

        public ObservableCollection<ContactBase> ManageableContacts
        {
            get
            {
                return manageableContacts;
            }
        }

        #endregion

        #region Methods

        private void ToolBarItem_MouseEnter(object sender, MouseEventArgs e)
        {
        }

        private void ToolBarItem_MouseLeave(object sender, MouseEventArgs e)
        {
        }

        private void manageableContacts_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (manageableContacts.Count > 0)
            {
                Visibility = Visibility.Visible;
            }
            else
            {
                Visibility = Visibility.Collapsed;
            }
            tbiChat.IsEnabled = manageableContacts.Count < 2;
            tbiConference.IsEnabled = manageableContacts.Count > 1;
            tbiProfile.IsEnabled = manageableContacts.Count < 2;
        }

        private void tbiChat_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Messenger.Conversations.OpenConversationWith(manageableContacts[0]);
        }

        private void tbiConference_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            List<IContact> list = new List<IContact>();
            foreach (ContactBase c in manageableContacts)
            {
                list.Add(c);
            }
            Messenger.Conversations.OpenConference(Guid.NewGuid().ToString(), list);
        }

        private void tbiProfile_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {

        }

        #endregion

    }

}